class Solution {
public:
    int minSwapsCouples(vector<int>& row) {
        int n = row.size();
        int ans = 0;
        map<int, int>mp;
        for (int i = 0; i < n; i++) {
            mp[row[i]] = i;
        }
        for (int i = 0; i < n; i += 2) {
            int x = row[i] ^ 1;
            if (row[i + 1] != x) {
                ans++;
                int idx = mp[x];
                cout << "idx==" << idx << endl;
                swap(row[idx], row[i + 1]);
                int temp = mp[row[i + 1]];
                mp[row[idx]] = mp[row[i + 1]];
                mp[row[i + 1]] = temp;
            }
        }
        for (auto x : row) {
            cout << x << " ";
        }
        cout << endl;
        return ans;
    }
};